import React, {useReducer} from "react";

// 2s 之后返回双倍的值
function doubleAfter2seconds(num) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(2 * num)
        }, 1000);
    } )
}

export default {
    state: {
        count: 0
    },

    reducers: {
        /*打开系统弹出窗口*/
        incrE1 (state, action) {
            return {count: state.count + 1, payload: action.payload};
        },
        decrE1 (state, action) {
            return {count: state.count - 1};
        },
      reset(state, action) {
        return {count: 0};
      }
    },
    effects: {
        async incr1(action, {call, put}) {
          put({ type: 'incrE1', payload: action.payload})
            console.log("2222222")
            let result = await doubleAfter2seconds(30);
            console.log(result);
            console.log("3333")
            // call({type: 'decr', payload: action.payload})
        },
        async decr1(action, {call, put}) {
          put({type: 'decrE1', payload: ''})
            let result = await doubleAfter2seconds(30);
            console.log(result);
          // call({type: 'incr', payload: action.payload})

        }
    }
}
